package jtable;

import java.awt.BorderLayout;
import java.awt.Container;
import java.util.ArrayList;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.TableColumn;

public class TableSample {
  public static void main(String args[]) {
    JFrame f = new JFrame("JTable Sample");
    Container content = f.getContentPane();
    ArrayList<Object[]> rows = new ArrayList<Object[]>();

    rows.add(new Object[]{ "AMZN", "Amazon", "67 9/16" });
    rows.add(new Object[]{ "BOUT", "About.com", "56 3/8" });
    rows.add(new Object[]{ "CDNW", "CDnow", "4 7/16" });
    
    String symbol= JOptionPane.showInputDialog ( null, "Enter Symbol: " );
    String name= JOptionPane.showInputDialog ( null, "Enter Name: " );
    String price= JOptionPane.showInputDialog ( null, "Enter Price: " );
    JOptionPane.showMessageDialog( null, "You entered: "+symbol+" "+name+" "+price );
    
    rows.add(new Object[]{symbol, name, price});
    
    Object rows1[][] = { { "AMZN", "Amazon", "67 9/16" },
        { "AOL", "America Online", "68 3/4" },
        { "BOUT", "About.com", "56 3/8" },
        { "CDNW", "CDnow", "4 7/16" },
        { "DCLK", "DoubleClick", "87 3/16" },
        { "EBAY", "eBay", "180 7/8" },
        { "EWBX", "EarthWeb", "18 1/4" },
        { "MKTW", "MarketWatch", "29" },
        { "TGLO", "Theglobe.com", "4 15/16" },
        { "YHOO", "Yahoo!", "151 1/8" } };
    for(int y=0; y<10; y++)
    {
    	for(int x=0; x<3; x++)
    		System.out.print(rows1[y][x]+" | ");
    	System.out.println();
    }
    Object rows2[][] = new Object[rows.size()][3];
    
    for(int y=0; y<rows.size(); y++)
    	for(int x=0; x<3;x++)
    	{
    		rows2[y][x]=rows.get(y)[x];
    	}
    System.out.println("------------------");
    for(int y=0; y<rows.size(); y++)
    {
    	for(int x=0; x<3; x++)
    		System.out.print(rows2[y][x]+" | ");
    	System.out.println();
    }
    Object columns[] = { "Symbol", "Name", "Price" };
    

    JTable table = new JTable(rows2, columns);
    
    System.out.println(table.getColumnName(0)+" "+table.getColumnName(1)+" "+table.getColumnName(2));
    JScrollPane scrollPane = new JScrollPane(table);
    content.add(scrollPane, BorderLayout.CENTER);
    f.setSize(300, 200);
    f.setVisible(true);
  }
}


